package logic

import (
	"context"
	"elem_svc/models/mysql"

	"elem_svc/elem"
	"elem_svc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopNameListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopNameListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopNameListLogic {
	return &ShopNameListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品列表
func (l *ShopNameListLogic) ShopNameList(in *elem.ShopNameListRequest) (*elem.ShopNameListResponse, error) {
	// todo: add your logic here and delete this line

	var shopNames []mysql.ShopName
	mysql.DB.Debug().Find(&shopNames)

	var shopNameList []*elem.ShopNameList
	for _, shop := range shopNames {
		list := elem.ShopNameList{
			ShopId: int64(shop.ShopId),
			Name:   shop.Name,
			Price:  float32(shop.Price),
			Stock:  int64(shop.Stock),
		}
		shopNameList = append(shopNameList, &list)
	}

	return &elem.ShopNameListResponse{
		List: shopNameList,
	}, nil
}
